package com.hmtech.ayp.common.resp;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class R<T> {
    private Integer code;
    private String msg;
    private T data;


    private R() {
    }

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> R<T> ok(T data) {
        return new R<>(BaseResultCode.SUCCESS.code, BaseResultCode.SUCCESS.message, data);
    }

    public static R<Void> unauthorized() {
        return new R<>(BaseResultCode.UNAUTHORIZED.code, BaseResultCode.UNAUTHORIZED.message, null);
    }

    public static R<Void> internalError() {
        return new R<>(BaseResultCode.INTERNAL_ERROR.code, BaseResultCode.INTERNAL_ERROR.message, null);
    }

    public static R<Void> ok() {
        R<Void> r = new R<>();
        r.setCode(200);
        r.setMsg("ok");
        return r;
    }
}
